{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d04efec8-c64a-451f-b86f-6104c70c7dd4",
   "metadata": {},
   "source": [
    "Chapter 05\n",
    "# 常用%占位符类型\n",
    "Book_1《编程不难》 | 鸢尾花书：从加减乘除到机器学习  \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "9044b18c-0782-4c5c-9caf-18ab93141f71",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'The first letter of Python is P'"
      ]
     },
     "execution_count": 1,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'The first letter of Python is %c' % 'P'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "48129124-eba3-4a2d-aabe-c53f90454851",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Welcome to the world of Python!'"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Welcome to the world of %s!' % 'Python'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "74add393-ca0a-4353-949d-66cea18376f8",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'Python has 6 letters.'"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'Python has %i letters.' % len('Python')"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "23189280-08f1-426a-bbd8-826e77194665",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Rounding 1.8888 to 2 decimal places is 1.89\n"
     ]
    }
   ],
   "source": [
    "number = 1.8888\n",
    "print(\"Rounding %.4f to 2 decimal places is %.2f\" % (number, number))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "d9b865fc-420e-498c-88f2-4157400d7a0c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12 in octal is 14\n"
     ]
    }
   ],
   "source": [
    "number = 12\n",
    "print(\"%i in octal is %o\" % (number, number))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "0f0e7025-e3bd-49fd-b409-202b0705eb6a",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "12000 is 1.20e+04\n"
     ]
    }
   ],
   "source": [
    "number = 12000\n",
    "print(\"%i is %.2e\" % (number, number))"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.10.9"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
